﻿using FinalTestMachine.Manger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace FinalTestMachine.Connect
{
    public class LightModulator_Connect
    {
        private SerialPortDemo3.ConnectSerialPortHelper connect;

        public LightModulator_Connect(SerialPortDemo3.ConnectSerialPortHelper LightModulator)
        {
            connect = LightModulator;
        }

        public void Channel1On()
        {
            string command = "4C 55 00 01 00 A2";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("打开工位4调光器通道1");
        }

        public void Channel1Off()
        {
            string command = "4C 55 00 00 00 A1";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("关闭工位4调光器通道1");
        }

        public void Channel2On()
        {
            string command = "4C 55 01 01 00 A3";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("打开工位4调光器通道2");
        }

        public void Channel2Off()
        {
            string command = "4C 55 01 00 00 A2";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("关闭工位4调光器通道2");
        }

        public void Channel3On()
        {
            string command = "4C 55 02 01 00 A4";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("打开工位4调光器通道3");
        }

        public void Channel3Off()
        {
            string command = "4C 55 02 00 00 A3";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("关闭工位4调光器通道3");
        }

        public void Channel4On()
        {
            string command = "4C 55 03 01 00 A5";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("打开工位4调光器通道4");
        }

        public void Channel4Off()
        {
            string command = "4C 55 03 00 00 A4";
            connect.SendBytes(HexStringToBytes(command));
            WriteToUser("关闭工位4调光器通道4");
        }
        /// <summary>
        /// 字符串转换为16进制字符数组
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static byte[] HexStringToBytes(string str)
        {
            string[] str_temp = str.Trim().Split(' ');
            byte[] bytes = new byte[str_temp.Length];
            for (int i = 0; i < str_temp.Length; i++)
            {
                bytes[i] = Convert.ToByte(str_temp[i], 16);
            }
            return bytes;
        }

        private static void WriteToUser(string str)
        {
            Motion.Process.Process_AutoRun.Cur.WriteToUser(str, Brushes.White, false);
        }
    }
}